package pers.hl.lib_global.model.bean

import android.os.Parcel
import android.os.Parcelable
import kotlinx.android.parcel.Parcelize
import pers.hl.lib_global.common.MMKVHelper

/**
 * {
"bookId": 6,
"bookName": "活着",
"bookIsbn": 888999,
"bookOwner": 1,
"bookFileId": 1,
"bookStatus": 1,
"bookDesc": "1",
"bookAuthor": null,
"bookTag": 0,
"bookLibId": 0
}
 */
@Parcelize
data class Book(
    var bookAuthor: String? = "佚名",
    var bookDesc: String? = "",
    var bookFileId: Int? = null,
    var bookId: Int? = null,
    var bookIsbn: Long? = null,
    var bookLibId: Int? = null,
    var bookName: String? = null,
    var bookOwner: Int? = null,
    var bookStatus: Int? = null,
    var bookTag: Int? = null,
    var tagName: String? = "",
    var bookLibStr: String? = null,
    var bookImg: String? = null,
    var ownerName: String? = "未知",
    var libName: String? = null,
    // 收藏状态，0：未收藏 1：已收藏
    var collect: Int? = 0
) : Parcelable {
    constructor(source: Parcel) : this(
        source.readString(),
        source.readString(),
        source.readInt(),
        source.readInt(),
        source.readLong(),
        source.readInt(),
        source.readString(),
        source.readInt(),
        source.readInt(),
        source.readInt(),
        source.readString(),
        source.readString(),
        source.readString(),
        source.readString(),
        source.readString(),
        source.readInt()
    )

    override fun describeContents() = 0

//    override fun writeToParcel(dest: Parcel, flags: Int): Unit = with(dest) {
//        writeString(bookAuthor)
//        writeString(bookDesc)
//        bookFileId?.let { writeInt(it) }
//        bookId?.let { writeInt(it) }
//        bookIsbn?.let { writeLong(it) }
//        bookLibId?.let { writeInt(it) }
//        writeString(bookName)
//        bookOwner?.let { writeInt(it) }
//        bookStatus?.let { writeInt(it) }
//        bookTag?.let { writeInt(it) }
//        writeString(tagName)
//        writeString(bookLibStr)
//        writeString(bookImg)
//        writeString(ownerName)
//        writeString(libName)
//        collect?.let { writeInt(it) }
//    }

    fun isCollect(): Boolean {
        return collect == 1
    }

    companion object {

        /**
         * 书籍状态 0：新发布 1：借阅中 2：已借阅(接受) 3：已归还 4：已取消 5：已拒绝 999：无意义，用于标记只修改特殊信息(二维码id)
         */
        const val STATUS_NEW = 0
        const val STATUS_BORROWING = 1
        const val STATUS_BORROWED = 2
        const val STATUS_RETURNED = 3
        const val STATUS_CANCEL = 4
        const val STATUS_REFUSED = 5

        const val STATUS_NONE = 999

//        @JvmField
//        val CREATOR: Parcelable.Creator<Book> = object : Parcelable.Creator<Book> {
//            override fun createFromParcel(source: Parcel): Book = Book(source)
//            override fun newArray(size: Int): Array<Book?> = arrayOfNulls(size)
//        }
    }
}